home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 634 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.3 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: jmac@interlog.com (John G. MacCulloch)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Re: Meaning of the specifier volatile?
  5. Date: 5 Jan 1996 09:11:19 -0000
  6. Organization: InterLog Internet Services
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: kanze@gabi-soft.fr
  9. Message-ID: <4cipvn$pma@netlab.cs.rpi.edu>
  10. References: <4c9740$27n@netlab.cs.rpi.edu> <4cb5i3$5mr@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12.  
  13. X-Original-Date: Fri, 05 Jan 96 06:16:22 GMT
  14.  
  15. In article <4cb5i3$5mr@netlab.cs.rpi.edu>,
  16.    Dave Nulton <dnult@axiom.net> wrote:
  17. >Path: news.interlog.com!winternet.com!uunet!in1.uu.net!news.mathworks.com!news.kei.com!ub!library.erc.clarkson.edu!rpi!not-for-mail
  18. >From: Dave Nulton <dnult@axiom.net>
  19. >Newsgroups: comp.lang.c++.moderated,comp.lang.c++
  20. >Subject: Re: Meaning of the specifier volatile?
  21. >Date: 2 Jan 1996 11:39:47 -0000
  22. >Organization: Axiom Communications
  23. >Lines: 24
  24. >Sender: cppmods@netlab.cs.rpi.edu
  25. >Approved: kanze@gabi-soft.fr
  26. >Message-ID: <4cb5i3$5mr@netlab.cs.rpi.edu>
  27. >References: <4c9740$27n@netlab.cs.rpi.edu>
  28. >NNTP-Posting-Host: netlab.cs.rpi.edu
  29. >Xref: news.interlog.com comp.lang.c++.moderated:518 comp.lang.c++:166027
  30. >Status: N
  31. >
  32. >X-Original-Date: 2 Jan 1996 07:22:26 GMT
  33. >
  34. >I'm no expert but here is what I know.  The specifier volatile is 
  35. >a directive to the compiler that the variable declared volatile 
  36. >can change at any moment.  The compiler will then make no 
  37. >assumptions about the contents of this variable, and will always 
  38. >re-check its value when used.  An example of something that might 
  39. >use volatile variables is:  a hardware interface to your PC which 
  40. >reads analog data and converts it to digital.  Your program may 
  41. >read the data from the PC bus.  However this data is always 
  42. >changing and your program should make know assumptions that the 
  43. >data is the same - it should always recheck the value.
  44. >
  45. >I'm sure there are other less complicated applications which may 
  46. >benefit from volatile variables.  I'm sure one of the many other 
  47. >experts on the net can elaborate.
  48. >
  49. >-dnult@axiom.net
  50. >
  51. >
  52. >    [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
  53. >    [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
  54. >    [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
  55. >    [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
  56.  
  57.  
  58. "volatile" can be handy in a multi-threaded program too.  Suppose you've got a flag that
  59. will be set in one thread to indicate that another thread can now proceed.  The flag needs
  60. to be marked as "volatile" because its value will magically change through an external 
  61. source (i.e. the other thread).  Without the "volatile" keyword, an optimizing compiler is probably 
  62. going to assume that the value of the flag can't change (resulting in an infinite loop -- not that 
  63. this has ever happened to me).
  64.  
  65. that is waiting for the flag to be set, the The thread
  66. that is waiting that indicates that another thread can 
  67.  
  68.     [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
  69.     [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
  70.     [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
  71.     [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
  72.